package org.common4j2ee.s2shs.entity.user;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.common4j2ee.s2shs.entity.IdEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.google.common.collect.Lists;

/**
 * 权限.
 * 
 * 注释见{@link User}.
 * 
 */
@Entity
@Table(name = "T_RESOURCES")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Resources extends IdEntity {


	private String name;
	
	private String type;
	
	private String resources;
	
	private Integer enabled;
	
	private Integer priority;
	
	private List<Authority> authList=Lists.newArrayList();

	public Resources() {
	}

	public Resources(Long id, String name) {
		this.id = id;
		this.name = name;
	}

	@Column(name="enabled")
	public Integer getEnabled() {
		return enabled;
	}

	public void setEnabled(Integer enabled) {
		this.enabled = enabled;
	}

	@Column(nullable = false, unique = true,name="name")
	public String getName() {
		return name;
	}
	@Column(name="srcType")
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	@Column(name="resources")
	public String getResources() {
		return resources;
	}

	public void setResources(String resources) {
		this.resources = resources;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="priority")
	public Integer getPriority() {
		return priority;
	}

	public void setPriority(Integer priority) {
		this.priority = priority;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	@ManyToMany
	@JoinTable(name = "T_AUTHORITY_RESOURCES", joinColumns = { @JoinColumn(name = "RESOURCES_ID") }, inverseJoinColumns = { @JoinColumn(name = "AUTHORITY_ID") })
	@Fetch(FetchMode.SUBSELECT)
	@OrderBy("id")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Authority> getAuthList() {
		return authList;
	}

	public void setAuthList(List<Authority> authList) {
		this.authList = authList;
	}
	
	
}
